package com.nhh.v.utils;

import com.nhh.exception.ServiceException;

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

/**
 * User: Allen.qin
 * Date: 2018/9/15
 */
public class UUIDUtils {
    private static final String CHARSET = "UTF-8";

    public static String generateUUID()   {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(uuid.getBytes(Charset.forName(CHARSET)), 0, uuid.length());
            return new BigInteger(1, messageDigest.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            throw new ServiceException("9001","Md5 error.",e);
        }

    }
}
